home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 4
/
Mac Giga-ROM 4.0 - 1993.toast
/
FILES
/
DEV
/
I-Z
/
Progress Tube Unit.cpt
/
Progress Tube Unit Folder
/
ProgressTube.c
< prev
next >
Wrap
Text File
|
1992-12-31
|
4KB
|
139 lines
/* (c) 1992-1993 Christopher Kline Chameleon Software */
/* This is declared to be "No Good Reason To Be Anything Other Than FreeWare" */
/* Anyone may use it without any compensation to me, as long as I receive some Email */
/* letting me know that you're using it (what a rush!). Hope you find it useful */
/* these routines need MacTraps, MacTraps2, and ANSI libraries to function */
#include "ProgressTube.h"
Rect defaultRect = {120, 70, 240, 440};
/*====================================================================================*/
OSErr NewTube(TubeType *theTube, Str255 theTitle)
{
Str255 titleChoice = kDefaultTubeTitle;
#define kAllocateMemoryForMe NULL
#define kShowTheProgressTubeNow TRUE
#define kNoCloseBox FALSE
#define kInFront (WindowPtr) -1
if (theTitle != NULL)
strcpy(titleChoice, theTitle); /* strcpy(destination, source) */
theTube->tubeWindow =
NewWindow ( kAllocateMemoryForMe, &defaultRect,titleChoice, kShowTheProgressTubeNow,
kDefaultTubeType, kInFront, kNoCloseBox, (long)"TUBE" );
SetRect(
&(theTube->tubeOutlineRect),
((*theTube).tubeWindow)->portRect.left + 20-1,
((*theTube).tubeWindow)->portRect.top + 55-1,
((*theTube).tubeWindow)->portRect.right - 20+1,
((*theTube).tubeWindow)->portRect.bottom - 50+1
); /* form: SetRect( &rect, left, top, right, bottom) */
if (theTube->tubeWindow != NULL)
return( noErr );
else
return( memFullErr);
}
/*====================================================================================*/
FillTube(TubeType theTube, Str255 *theString, float *thePercentage)
{
Rect fillRect;
GrafPtr savedPort;
Str255 messageChoice = kDefaultTubeMessage;
if (*theString != NULL)
strcpy(messageChoice, *theString); /* strcpy(destination, source) */
GetPort( &savedPort ); /* remember the previous grafport */
SetPort(theTube.tubeWindow);
ForeColor(blackColor);
FrameRect( &theTube.tubeOutlineRect ); /*outline the fill bar */
TextFont( kDefaultFontNum );
TextSize( kDefaultFontSize );
TextMode( srcCopy );
MoveTo( theTube.tubeWindow->portRect.left + 20, theTube.tubeWindow->portRect.top + 35 );
DrawString( messageChoice );
DrawString( "\p " );
ForeColor(kDefaultTubeColor);
SetRect(
&fillRect,
theTube.tubeWindow->portRect.left + 20,
theTube.tubeWindow->portRect.top + 55,
(theTube.tubeWindow->portRect.right - 20) * (*thePercentage),
theTube.tubeWindow->portRect.bottom - 50
); /* form: SetRect( &rect, left, top, right, bottom) */
if (*thePercentage <= 1 ) /* don't overflow the fill tube! */
PaintRect( &fillRect );
SetPort( savedPort ); /* restore the previous grafport */
}
/*====================================================================================*/
ResetTube(TubeType theTube)
{
GrafPtr savedPort;
GetPort( &savedPort ); /* remember the previous grafport */
SetPort(theTube.tubeWindow);
EraseRect( &theTube.tubeOutlineRect );
SetPort( savedPort ); /* restore the previous grafport */
}
/*====================================================================================*/
DisposeTube(TubeType theTube)
{
if (theTube.tubeWindow != NULL)
DisposeWindow(theTube.tubeWindow);
}
/*====================================================================================*/
CenterTube(TubeType theTube)
{
Rect r;
int width,
height,
sWidth,
sHeight,
h,
v;
r = theTube.tubeWindow->portRect;
width = r.right - r.left;
height = r.bottom - r.top;
sWidth = screenBits.bounds.right - screenBits.bounds.left;
sHeight = screenBits.bounds.bottom - screenBits.bounds.top;
h = screenBits.bounds.left + ( (sWidth - width) / 2 );
v = screenBits.bounds.top + ( (sHeight - height) / 2 );
MoveWindow( theTube.tubeWindow, h, v, FALSE );
}